package com.resou.reader.bookdetail.comment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.resou.reader.R;
import com.resou.reader.base.ResouBaseActivity;
import com.resou.reader.bookdetail.adapter.CommentAdapter;
import com.resou.reader.bookdetail.comment.fragment.FragmentHot;
import com.resou.reader.bookdetail.comment.fragment.FragmentNow;
import com.resou.reader.bookdetail.comment.release.ReleaseCommentActivity;
import com.resou.reader.bookstore.rank.adapter.FragmentAdapter;
import com.resou.reader.view.MagincIndicatorAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.abs.IPagerNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description:评论页面
 * CreateTime: 2019-04 -10
 **/
public class CommentListActivity extends ResouBaseActivity<CommentPresenter> implements ICommentContract.ICommentView, ViewPager.OnPageChangeListener {

    public static void start(Context context, String bookId, String bookName) {
        Intent starter = new Intent(context, CommentListActivity.class);
        starter.putExtra("bookId", bookId);
        starter.putExtra("bookName", bookName);
        context.startActivity(starter);
    }

    @BindView(R.id.mMagicIndicator)
    MagicIndicator mMagicIndicator;

    @BindView(R.id.mViewPager)
    ViewPager mViewPager;
    @BindView(R.id.rlBottom)
    RelativeLayout rlBottom;
    @BindView(R.id.root_layout)
    RelativeLayout rootLayout;
    List<String> list = null;

    List<Fragment> mList;
    public String mBookId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_recommend;
    }

    @Override
    public void retryRefreshData() {

    }

    @Override
    protected void initStatusBar() {

    }

    @Override
    protected void initPresenter() {
        mPresenter = new CommentPresenter(this, mBookId);
    }

    @Override
    protected void initView() {
        mBookId = getIntent().getStringExtra("bookId");
        list = new ArrayList<>();
        list.add("最新评论");
        list.add("热门评论");
        mList = new ArrayList<>();
        FragmentNow fragmentNow = new FragmentNow();
        Bundle bundle = new Bundle();
        bundle.putString("mBookId", mBookId);
        fragmentNow.setArguments(bundle);
        mList.add(fragmentNow);
        FragmentHot fragmentHot = new FragmentHot();
        bundle.putString("mBookId", mBookId);
        fragmentHot.setArguments(bundle);
        mList.add(fragmentHot);
        bindViewPager();
    }

    /**
     * 绑定Viewpager与mMagicIndicator
     */
    private synchronized void bindViewPager() {
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), mList);
        mViewPager.setAdapter(fragmentAdapter);
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdjustMode(true);
        mViewPager.addOnPageChangeListener(this);
        mViewPager.setCurrentItem(0);
        MagincIndicatorAdapter magincIndicatorAdapter = new MagincIndicatorAdapter(this.list, mViewPager);
        magincIndicatorAdapter.setBottomLineColor(getResources().getColor(R.color.white)).
                setNormalColor(getResources().getColor(R.color.white))
                .setSelectColor(getResources().getColor(R.color.white));
        commonNavigator.setAdapter(magincIndicatorAdapter);
        mMagicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(mMagicIndicator, mViewPager);
    }

    @Override
    public void initData() {

    }

    @Override
    public void showContent() {

    }

    @Override
    public void showProgress() {

    }

    @Override
    public void showError(Throwable throwable) {

    }

    @Override
    public void showEmpty() {

    }

    @OnClick({R.id.ivBack, R.id.rlBottom})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivBack:
                finish();
                break;
            case R.id.rlBottom:
                ReleaseCommentActivity.start(CommentListActivity.this, mBookId);
                break;
        }
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int i) {

    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }
}
